package com.imooc.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.imooc.service.ListService;


/*
 * 淚飆頁面控制器
 * 
 */
@SuppressWarnings("serial")
public class ListServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// 设置编码格式
		req.setCharacterEncoding("UTF-8");
		// 获取页面数据
		String command = req.getParameter("command");
		String description = req.getParameter("description");
		// 给回页面数据
		req.setAttribute("command", command);
		req.setAttribute("description", description);

		ListService listService = new ListService();
		// 根据查询条件获取数据
		req.setAttribute("messageList", listService.queryMessageList(command, description));
		// 数据传给页面
		req.getRequestDispatcher("WEB-INF/jsp/back/list.jsp").forward(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
